<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <link rel="stylesheet" th:href="@{/css/bootstrap.min.css}">
    <script th:src="@{/js/jquery-1.10.2.min.js}"></script>
    <script th:src="@{/js/bootstrap.min.js}"></script>
    <script th:src="@{/js/echarts.min.js}"></script>
    <title>注册</title>
</head>
<body>
<div class="container">
    <div class="row clearfix">
        <div class="col-md-2 column">
        </div>
        <div class="col-md-8 column">
            <h3 class="text-center">
                注册界面
            </h3>
            <form class="form-horizontal" role="form" action="/doReg" method="post">
                <div class="form-group">
                    <label for="username" class="col-sm-4 control-label">用户名*</label>
                    <div class="col-sm-6">
                        <input type="text" name="username" id="username" placeholder="请输入用户名" required/><span id="exist1"></span>
                    </div>
                </div>
                <div class="form-group">
                    <label for="pass" class="col-sm-4 control-label">密码*</label>
                    <div class="col-sm-6">
                        <input type="password" name="pass" id="pass" placeholder="请输入密码" required/>
                    </div>
                </div>
                <div class="form-group">
                    <label for="pass1" class="col-sm-4 control-label">确认密码*</label>
                    <div class="col-sm-6">
                        <input type="password" name="pass1" id="pass1" placeholder="请再次输入密码" required/><span id="tp1"></span>
                    </div>
                </div>
                <div class="form-group">
                    <label for="tel" class="col-sm-4 control-label">手机*</label>
                    <div class="col-sm-6">
                        <input type="text" name="tel" id="tel" placeholder="请输入手机号"><span id="exist2"></span>
                    </div>
                </div>
                <div class="form-group">
                    <label for="yzm" class="col-sm-4 control-label">验证码*</label>
                    <div class="col-sm-6">
                        <input type="text" name="yzm" id="yzm" placeholder="请输入验证码"><input type="button" value="发送验证码">
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-offset-4 col-sm-5">
                        <button type="submit" class="btn btn-default btn-primary" style="width:150px">注册</button>
                    </div>
                </div>
            </form>
        </div>
        <div class="col-md-2 column">
        </div>
    </div>
</div>
</body>

<script>
    $(function () {
        var objUsername = $("#username");//选取账号输入
        //触发失去焦点事件
        objUsername.blur(function () {
            //
            //异步送出数据，至控制层，测试是否存在此账号
            $.ajax({
                type: "post", //访问方式
                url: "/customer/usernameIsExist", //访问路径
                data: {//传入服务端的数据
                    "username": objUsername.val()
                },
                dataType: "json",
                //contentType: "application/json;charset=utf-8"
                // contentType: "application/json;charset=utf-8",
                success: function (message) {
                    if (message == '1') {
                        objUsername.focus();
                        $('#exist1').html("账号已被占用");
                        $('#exist1').css("color", "red");
                    } else {
                        $('#exist1').html("账号可使用");
                        $('#exist1').css("color", "green");
                    }
                },
                error: function (err) {
                    alert("请求出错了" + JSON.stringify(err));
                }
            });//end of ajax
        });//end of blur


        var objTel = $("#tel");//选取账号输入框
        //触发失去焦点事件
        objTel.blur(function () {
            //
            //异步送出数据，至控制层，测试是否存在此账号
            $.ajax({
                type: "post", //访问方式
                url: "/customer/telIsExist", //访问路径
                data: {//传入服务端的数据
                    "tel": objTel.val()
                },
                dataType: "json",
                //contentType: "application/json;charset=utf-8"
                // contentType: "application/json;charset=utf-8",
                success: function (message) {
                    if (message == '1') {
                        objTel.focus();
                        $('#exist2').html("手机号已被占用");
                        $('#exist2').css("color", "red");
                    } else {
                        $('#exist2').html("手机号可使用");
                        $('#exist2').css("color", "green");
                    }
                },
                error: function (err) {
                    alert("请求出错了" + JSON.stringify(err));
                }
            });//end of ajax
        });//end of blur
        var pass1 = $("#pass1");//选取账号输入

        pass1.blur(function () {
            //
            //异步送出数据，至控制层，测试是否存在此账号
            $.ajax({
                type: "post", //访问方式
                url: "/customer/passIsExist", //访问路径
                data: {//传入服务端的数据
                    "pass1": pass1.val()
                },
                dataType: "json",
                //调整成功后事件 message为服务器返回的值
                success: function () {
                        if($("#pass").val()!=$("#pass1").val()){
                            $('#tp1').html("二次密码不一致");
                            $('#tp1').css("color", "red");
                            pass1.focus();
                        }else{
                            $('#tp1').html("");
                            // $('#tp').css("color", "red");
                        }
                },
                //若调用错误，则执行此事件
                error: function (err) {
                    alert("请求出错了" + JSON.stringify(err));
                }
            });//end of ajax
        });//end of blur
    })
</script>
</html>